package dd.prog2.exercises.set10;

import java.io.File;
import java.io.IOException;

public class FlexibleFileTreeWalker{

	private FileProcessor fp;
	
	public FlexibleFileTreeWalker(FileProcessor fp) {
		this.fp = fp;
	}

	public void walk(String pathname) throws IOException {
		File[] files = new File(pathname).listFiles();
		if (files != null) {
			for (File file : files)
				if (file.isDirectory())
					walk(file.getCanonicalPath());
				else
					fp.process(file);
		}
	}

	static interface FileProcessor {
		void process(File file) throws IOException;
	}
}
